<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>
	<body>

		<table class="layui-hide" id="test" lay-filter="test"></table>
		<span id="show" style="display:none">123</span>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
  			</div>
</script>
		<script type="text/html" id="barDemo">
</script>


		<script src="/static/layui/layui.js" charset="utf-8"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

		<script>
			layui.use(['table', 'laypage', 'jquery', 'form', 'laydate'], function() {
				var table = layui.table;
				var $ = layui.$;
				var form = layui.form;

				table.render({

					elem: '#test',
					url: '/school/studentList',
					toolbar: '#toolbarDemo',
					title: '用户数据表',
					totalRow: true,
					cols: [
						[{
							type: 'checkbox',
							fixed: 'left'
						}, {
							// totalRowText: '合计',
							field: 'nickName',
							title: '申请人微信昵称',
							width: 180,
							// fixed: 'left',
							unresize: true,
							sort: true,

						}, {
							field: 'openId',
							title: '微信openId',
							width: 300,
							edit: 'text'
						}, {
							field: 'jwcAccount',
							title: '学号',
							width: 200,
							sort: true,
							// totalRow: true
						}, {
							field: 'qualityFraction',
							title: '素质拓展分数',
							width: 200,
							edit: 'text',
							sort: true
						}, {
							field: 'comprehensiveFraction',
							title: '综测',
							width: 200
						}, {
							field: 'grade',
							title: '年级',
							width: 200
						}, {
							field: 'department',
							title: '学院',
							width: 200
						}]
					],
					page: false,


				});




				var arr = [];
				table.on('checkbox(test)', function(obj) {
					var flg = 0;
					if (obj.type != 'all') {
						if (arr.length == 0) {
							if (obj.checked == true) {
								arr.push(obj);

							}
						} else {
							$.each(arr, function(index, value) {
								if (obj.data.id == value.data.id) {
									flg = 1;
									if (obj.checked == false) {
										arr.splice(index, 1);
									}
								} else {
									flg = 0;
								}

							});
							if (flg == 0) {
								arr.push(obj);
							}
						}
					}
				});






				//工具栏事件
				table.on('toolbar(test)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);

					// 					console.log(table.checkStatus(obj.config.id));
					// console.log(obj.config.elem)

					switch (obj.event) {
						case 'getCheckData':
							var data = checkStatus.data;
							$(this).parent().parent().parent().parent().toggle();
							$("#show").toggle();
							$("#all").toggle();
							console.log(data)
							$('#show').html(JSON.stringify(data))
							break;
						case 'getCheckLength':
							var data = checkStatus.data;
							console.log(checkStatus)
							layer.msg('选中了：' + data.length + ' 个');
							break;
						case 'isAll':
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
							break;
					};
				});
				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;

					if (obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							// console.log(obj);
							obj.del();
							layer.close(index);
						});
					} else if (obj.event === 'edit') {
						console.log(obj.data);
						
						$('#show').html(JSON.stringify(data));
						$("#show").toggle();
						var table = $(this).parents().find(".layui-form")[0]
						$(table).toggle();

					}
				});
			});
		</script>
	</body>
</html>
